package com.demo.controller;

import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @program: spring-demo2
 * @author: JCM
 * @create: 2023-06-12 11:47
 * @description:
 **/
@Controller
public class StudentController {
    // 1. 使用属性注入获取 Bean

    @Autowired

    @Resource
    private StudentService studentService;

//    2.使用 set 方法注入
//    private StudentService studentService;
//    @Autowired
//    public void setStudentService(StudentService studentService) {
//        this.studentService = studentService;
//    }

    // 使用构造方法注入
//    private StudentService studentService;
//
//    @Autowired
//    public StudentController(StudentService studentService) {
//        this.studentService = studentService;
//    }
//
    public void sayHi() {
        //
        System.out.println("执行了 StudentController sayHi 方法");
        studentService.sayHi();

    }

}
